package com.scorpio.api.controller.basic;


import java.util.List;

import com.scorpio.basic.domain.HomeListResEntity;
import com.scorpio.basic.service.IHomeListResService;
import com.scorpio.basic.vo.HomeListResVo;
import com.scorpio.basic.vo.OperationIdVo;
import com.scorpio.common.core.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.scorpio.common.annotation.Log;
import com.scorpio.common.core.controller.BaseController;
import com.scorpio.common.core.domain.AjaxResult;
import com.scorpio.common.enums.BusinessType;
import com.scorpio.basic.domain.HomeListEntity;
import com.scorpio.basic.service.IHomeListService;
import com.scorpio.common.utils.poi.ExcelUtil;
import org.springframework.validation.annotation.Validated;
import com.scorpio.common.utils.verification.AddGroup;
import com.scorpio.common.utils.verification.DefaultGroup;
import com.scorpio.common.utils.verification.UpdateGroup;


/**
 * 首页列数据Controller
 *
 * @author scorpio
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/basic/home_list")
public class HomeListController extends BaseController {
    @Autowired
    private IHomeListService service;

    @Autowired
    private IHomeListResService resService;

    /**
     * 查询首页列数据列表
     */
    @PreAuthorize("@ss.hasPermi('basic:home_list:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeListEntity homeList) {
        startPage();
        List<HomeListEntity> list = service.selectList(homeList);
        return getDataTable(list);
    }

    @GetMapping("/styleList")
    public AjaxResult styleList(@Validated OperationIdVo vo) {
        return AjaxResult.success(resService.selectByHomeList(vo.getId()));
    }

    /**
     * 获取首页列数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:home_list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(service.selectById(id));
    }

    /**
     * 新增首页列数据
     */
    @PreAuthorize("@ss.hasPermi('basic:home_list:add')")
    @Log(title = "首页列数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(value = {AddGroup.class, DefaultGroup.class}) HomeListEntity entity) {
        return toAjax(service.save(entity));
    }

    /**
     * 修改首页列数据
     */
    @PreAuthorize("@ss.hasPermi('basic:home_list:edit')")
    @Log(title = "首页列数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(value = {UpdateGroup.class, DefaultGroup.class}) HomeListEntity entity) {
        return toAjax(service.update(entity));
    }

    /**
     * 删除首页列数据
     */
    @PreAuthorize("@ss.hasPermi('basic:home_list:remove')")
    @Log(title = "首页列数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(service.deleteByIds(ids));
    }


    /**
     * 新增首页列资源
     */
    @PreAuthorize("@ss.hasPermi('basic:home_list:edit')")
    @Log(title = "首页列资源", businessType = BusinessType.INSERT)
    @PostMapping("/updateRes")
    public AjaxResult updateRes(@RequestBody @Validated(value = {AddGroup.class, DefaultGroup.class}) HomeListResVo vo) {
        return toAjax(resService.save(vo));
    }

}
